package cn.sirun.com.fca.account.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.githang.statusbar.StatusBarCompat;
import com.jungly.gridpasswordview.GridPasswordView;
import com.tencent.cloud.iov.router.Router;
import com.tencent.cloud.iov.util.ActivityUtils;
import com.tencent.cloud.iov.util.ResourcesUtils;
import com.tencent.cloud.uikit.ui.BaseIovActivity;
import com.tencent.cloud.uikit.utils.SystemUiUtils;

import cn.sirun.com.fca.account.R;
import cn.sirun.com.fca.account.constant.AccountActivityConst;
import cn.sirun.com.fca.account.constant.AccountIntentConst;
import cn.sirun.com.fca.account.constant.CaptchaConst;

public class SettingNewPinActivity extends BaseIovActivity {
    private GridPasswordView mPinGPV;
    private TextView mNextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting_new_pin_activity);
        StatusBarCompat.setStatusBarColor(this,
                ResourcesUtils.getColor(cn.sirun.com.fca.account.R.color.bg_color_primary));
        SystemUiUtils.showActionBar(this, "");
        initView();
    }

    private void initView() {
        mPinGPV = this.findViewById(R.id.gpv_pin);
        mNextView = this.findViewById(R.id.tv_next);

        mPinGPV.togglePasswordVisibility();

        mPinGPV.setOnPasswordChangedListener(new GridPasswordView.OnPasswordChangedListener() {
            @Override
            public void onTextChanged(String psw) {
                if (psw.length() == CaptchaConst.PIN_LENGTH) {
                    mNextView.setBackgroundResource(R.drawable.s_btn_bg_border);
                    mNextView.setEnabled(true);
                } else {
                    mNextView.setBackgroundResource(R.drawable.s_btn_default_bg_border);
                    mNextView.setEnabled(false);
                }
            }

            @Override
            public void onInputFinish(String psw) {
            }
        });

        mNextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = Router.fromPath(AccountActivityConst.Path.STRING_PIN_AGAIN);
                intent.putExtra(AccountIntentConst.SETTING_PIN, mPinGPV.getPassWord());
                ActivityUtils.startActivityForResult(SettingNewPinActivity.this, intent);
            }
        });
    }

}
